<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of stats
 *
 * @author b4by
 */
class rankstats extends MY_Controller {

	public function index($freq = '', $limit = '') {

		if (!$data = $this->cache->file->get('rankstats_' . $freq . $limit)) {
			if ($limit > 3 * 100)
				$limit = 300;
			if (!$this->ajax && !is_numeric($limit))
				$limit = $this->siteConfig->top_users;
			$users = $this->getTopUser($freq, $limit);
			$data = array();
			foreach ($users as $user) {
				$row = new stdClass();
				$row->fullname = $this->ajax ? striplongstr($user->fullname) : striplongstr($user->fullname, 30);
				$row->avatar = fb_avatar($user->fb_id);
				$row->likes = $user->likes;
				if ($freq == 'week')
					$row->likes = $user->week;
				if ($freq == 'month')
					$row->likes = $user->month;
				$row->link = url_create('site', 'account', 'images', $user->id);
				$data[] = $row;
			}
			$this->cache->save('rankstats_' . $freq . $limit, $data, 60);
		}
		error_reporting(0);
		if ($this->ajax)
			echo json_encode(array(
				'state' => 'success',
				'data' => $data,
			));
		else {
			$this->data['freq'] = $freq;
			$this->data['users'] = $data;
			$this->data['temp'] = 'rankstats/index';
			$this->loadView();
		}
	}

}

?>
